home *** CD-ROM | disk | FTP | other *** search
/ Introduction to 3D Game …ogramming with DirectX 12 / Introduction-to-3D-Game-Programming-with-DirectX-12.ISO / Code.Textures / Chapter 13 The Compute Shader / WavesCS / GpuWaves.h < prev    next >
Encoding:
C/C++ Source or Header  |  2016-03-02  |  2.6 KB  |  90 lines

  1. //***************************************************************************************
  2. // GpuWaves.h by Frank Luna (C) 2011 All Rights Reserved.
  3. //
  4. // Performs the calculations for the wave simulation using the ComputeShader on the GPU.  
  5. // The solution is saved to a floating-point texture.  The client must then set this 
  6. // texture as a SRV and do the displacement mapping in the vertex shader over a grid.
  7. //***************************************************************************************
  8.  
  9. #ifndef GPUWAVES_H
  10. #define GPUWAVES_H
  11.  
  12. #include "../../Common/d3dUtil.h"
  13. #include "../../Common/GameTimer.h"
  14.  
  15. class GpuWaves
  16. {
  17. public:
  18.     // Note that m,n should be divisible by 16 so there is no 
  19.     // remainder when we divide into thread groups.
  20.     GpuWaves(ID3D12Device* device, ID3D12GraphicsCommandList* cmdList, int m, int n, float dx, float dt, float speed, float damping);
  21.     GpuWaves(const GpuWaves& rhs) = delete;
  22.     GpuWaves& operator=(const GpuWaves& rhs) = delete;
  23.     ~GpuWaves()=default;
  24.  
  25.     UINT RowCount()const;
  26.     UINT ColumnCount()const;
  27.     UINT VertexCount()const;
  28.     UINT TriangleCount()const;
  29.     float Width()const;
  30.     float Depth()const;
  31.     float SpatialStep()const;
  32.  
  33.     CD3DX12_GPU_DESCRIPTOR_HANDLE DisplacementMap()const;
  34.  
  35.     UINT DescriptorCount()const;
  36.  
  37.     void BuildResources(ID3D12GraphicsCommandList* cmdList);
  38.  
  39.     void BuildDescriptors(
  40.         CD3DX12_CPU_DESCRIPTOR_HANDLE hCpuDescriptor,
  41.         CD3DX12_GPU_DESCRIPTOR_HANDLE hGpuDescriptor,
  42.         UINT descriptorSize);
  43.  
  44.     void Update(
  45.         const GameTimer& gt,
  46.         ID3D12GraphicsCommandList* cmdList, 
  47.         ID3D12RootSignature* rootSig,
  48.         ID3D12PipelineState* pso);
  49.  
  50.     void Disturb(
  51.         ID3D12GraphicsCommandList* cmdList,
  52.         ID3D12RootSignature* rootSig,
  53.         ID3D12PipelineState* pso, 
  54.         UINT i, UINT j, 
  55.         float magnitude);
  56.  
  57. private:
  58.  
  59.     UINT mNumRows;
  60.     UINT mNumCols;
  61.  
  62.     UINT mVertexCount;
  63.     UINT mTriangleCount;
  64.  
  65.     // Simulation constants we can precompute.
  66.     float mK[3];
  67.  
  68.     float mTimeStep;
  69.     float mSpatialStep;
  70.  
  71.     ID3D12Device* md3dDevice = nullptr;
  72.  
  73.     CD3DX12_GPU_DESCRIPTOR_HANDLE mPrevSolSrv;
  74.     CD3DX12_GPU_DESCRIPTOR_HANDLE mCurrSolSrv;
  75.     CD3DX12_GPU_DESCRIPTOR_HANDLE mNextSolSrv;
  76.  
  77.     CD3DX12_GPU_DESCRIPTOR_HANDLE mPrevSolUav;
  78.     CD3DX12_GPU_DESCRIPTOR_HANDLE mCurrSolUav;
  79.     CD3DX12_GPU_DESCRIPTOR_HANDLE mNextSolUav;
  80.  
  81.     // Two for ping-ponging the textures.
  82.     Microsoft::WRL::ComPtr<ID3D12Resource> mPrevSol = nullptr;
  83.     Microsoft::WRL::ComPtr<ID3D12Resource> mCurrSol = nullptr;
  84.     Microsoft::WRL::ComPtr<ID3D12Resource> mNextSol = nullptr;
  85.  
  86.     Microsoft::WRL::ComPtr<ID3D12Resource> mPrevUploadBuffer = nullptr;
  87.     Microsoft::WRL::ComPtr<ID3D12Resource> mCurrUploadBuffer = nullptr;
  88. };
  89.  
  90. #endif // GPUWAVES_H